<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 14-10-23
 * Time: 上午9:36
 * @author 郑钟良<zzl@ourstu.com>
 */
require_once(APP_PATH . 'Help/Common/function.php');
function answer_can_support($answer_id){
    if(!is_login()){
        return false;
    }
    $map['uid']=is_login();
    $map['answer_id']=$answer_id;
    $result=D('QuestionAnswerSupport')->where($map)->find();
    if($result) return false;
    return true;
}

function get_support_type($answer_id){
    if(!is_login()){
        return -1;
    }
    $map['uid']=is_login();
    $map['answer_id']=$answer_id;
    $result=D('QuestionAnswerSupport')->where($map)->find();
    if($result) return $result['type'];
    return -1;
}
/**
 * @param $question 问题的id
 * @param $answer   答案的id
 * @param $response 回复的id
 * @param $from_id  消息发送者id
 * @return bool
 * @author 郑钟良<zzl@ourstu.com>
 */
function send_question_answer_message($question,$answer,$response,$from_id){
    $userInfo=query_user(array('nickname'),$from_id);
    if($answer){
        $to_uid_first=D('Question/QuestionAnswer')->getUidById($answer);
        sendMessage($to_uid_first,$userInfo['nickname'].'评价了您的答案','问题：您得到了新评价',U('question/index/detail',array('id'=>$question)),$from_id,1);
        $to_uid_second=D('Question/QuestionAnswer')->getUidById($response);
        sendMessage($to_uid_second,$userInfo['nickname'].'回复了您的评价','问题：您得到了新回复',U('question/index/detail',array('id'=>$question)),$from_id,1);
    }else{
        $to_uid=D('Question/Question')->getUidById($question);
        sendMessage($to_uid,$userInfo['nickname'].'回答了您的问题','问题：您得到了新答案',U('question/index/detail',array('id'=>$question)),$from_id,1);
    }
    return true;
}

/**
 * @param $ids 问题id数组
 * @return bool
 * @author 郑钟良<zzl@ourstu.com>
 */
function send_good_question_mssage($ids){
    foreach($ids as $val){
        $to_uid=D('Question/Question')->getUidById($val);
        sendMessage($to_uid,'管理员把您的问题设为了好问题','问题：问题被设为好问题',U('question/index/detail',array('id'=>$val)));
    }
    unset($val);
    return true;
}